<html>
<head>
    <title>会员管理</title>
    <link href="/lib/layui/css/layui.css" rel="stylesheet"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item" style="margin-top:15px ">
        <div class="layui-inline">
            <label class="layui-form-label">会员用户名</label>
            <div class="layui-input-inline">
                <input type="text" id="input1" name="username" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline layui-input-wrap">
                <select id="select1">
                    <option value="1" selected>正常</option>
                    <option value="2">停用</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <input id="searchBtn" type="button" value="查询" class="layui-btn">
            <input id="delBtn" type="button" value="停用" class="layui-btn">
            <input id="resetBtn" type="button" value="重置密码" class="layui-btn">
        </div>
    </div>
</form>

<script src="/lib/layui/layui.js"></script>
<script src="/js/common.js"></script>
<table id="table1"></table>
<!-- 弹出窗口的模板 -->
<script id="template1" type="text/html">
    <form class="layui-form" action="" lay-filter="form1">

        <div id="passworddiv" class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input id="password" type="text" name="password" autocomplete="off" class="layui-input">
                    <input type="hidden" name="id"/>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="reset" value="重置" class="layui-btn layui-btn-primary">
                <input type="button" id="saveBtn" value="保存" class="layui-btn">
            </div>
        </div>
    </form>

</script>

<!--表头编辑删除模板-->
<script id="template2" type="text/html">
<!--    <input lay-event="edit" type="button" value="编辑" class="layui-btn layui-btn-xs">-->

</script>



<script th:inline="none">
    layui.use(["layer", "form", "table", "upload"], function () {
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;


        //给多选停用按钮绑事件
        $("#delBtn").on("click", function () {
            var o = table.checkStatus("table1")
            if (o.data.length == 0) {
                layer.msg("至少选中一行")
                return false;
            }
            layer.confirm("您确定要停用选中的账号吗？", function () {
                var ids = "";
                $.each(o.data, function (index, item) {
                    if (ids) {
                        ids += ",";
                    }
                    ids += item.id;
                });
                $.post("/member/updateAll", {ids: ids}, function () {
                    layer.closeAll();
                    layer.msg("停用成功");
                    $("#searchBtn").click();
                });
            });
        });

        $("#searchBtn").on("click", function () {
            table.render({
                elem: "#table1",
                cols: [[
                    {title: "选择", type: "checkbox"},
                    {title: "序号", type: "numbers"},
                    {title: "用户名", field: "username"},
                    {title: "电话号码", field: "tel"},
                    {title: "性别", field: "sex"},
                    {title: "邮箱", field: "email"},
                ]],
                url: "/member/list",
                where: {username: $("#input1").val(),status: $("#select1").val()},
                //分页操作
                page: true,
                //每页显示多少条
                limits: [5, 10, 20],
                limit: 5
            });
        }).click();



        //给多选停用按钮绑事件
        $("#resetBtn").on("click", function () {
            var o = table.checkStatus("table1")
            if (o.data.length == 0) {
                layer.msg("至少选中一行")
                return false;
            }
            layer.confirm("您确定要重置选中账号的密码吗？", function () {
                var ids = "";
                $.each(o.data, function (index, item) {
                    if (ids) {
                        ids += ",";
                    }
                    ids += item.id;
                });
                $.post("/member/resetAll", {ids: ids}, function () {
                    layer.closeAll();
                    layer.msg("重置成功！默认密码为123456");
                    $("#searchBtn").click();
                });
            });
        });


    })


</script>


</body>
</html>